package com.shhm.business.controller;

import com.shhm.business.service.ProductService;
import com.shhm.common.annotations.OperateLog;
import com.shhm.common.dto.request.RequestList;
import com.shhm.common.dto.response.AjaxResultPlus;
import com.shhm.common.dto.response.business.ProductVO;
import com.shhm.common.entity.common.ProductEntity;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import org.springframework.web.bind.annotation.*;

/**
 * @author JackZ
 * @version 1.0
 * @description: TODO
 * @date 2025/9/2 下午3:09
 */
@RestController
public class ProductController {
    @Resource
    private ProductService productService;

    @GetMapping("/admin/product")
    public AjaxResultPlus pageList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1") Integer isPage,
            HttpServletRequest request
    ){
        return productService.shelvesList(pageNum,pageSize,isPage,request);
    }

    @PostMapping("/admin/product/search")
    public AjaxResultPlus pageSearchList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestBody ProductVO entity,
            HttpServletRequest request
    ){
        return productService.pageSearchList(pageNum,pageSize,entity,request);
    }

    @PostMapping("/admin/product")
    @OperateLog(module="商品管理",type = "POST",desc = "添加商品信息")
    public AjaxResultPlus add(@RequestBody ProductEntity entity,HttpServletRequest request){
        return productService.add(entity,request);
    }

    @PutMapping("/admin/product")
    @OperateLog(module="商品管理",type = "PUT",desc = "修改商品信息")
    public AjaxResultPlus update(@RequestBody ProductEntity entity, HttpServletRequest request){
        return productService.updateProductEntity(entity,request);
    }

    @DeleteMapping("/admin/product")
    @OperateLog(module="商品管理",type = "DELETE",desc = "删除商品")
    public AjaxResultPlus delete(@RequestBody RequestList ids,HttpServletRequest request){
        return productService.delete(ids,request);
    }

    @PutMapping("/admin/product/audit")
    @OperateLog(module="商品审核管理",type = "PUT",desc = "审核商品")
    public AjaxResultPlus auditProduct(@RequestBody ProductVO entity, HttpServletRequest request){
        return productService.auditProduct(entity,request);
    }

    @GetMapping("/admin/product/audit")
    public AjaxResultPlus auditList(
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            @RequestParam(defaultValue = "1") Integer isPage,
            HttpServletRequest request
    ){
        return productService.auditProductList(pageNum,pageSize,isPage,request);
    }

    @PostMapping("/admin/product/audit/search")
    public AjaxResultPlus auditSearchList(
            @RequestBody ProductVO entity,
            @RequestParam(defaultValue = "1") Integer pageNum,
            @RequestParam(defaultValue = "10") Integer pageSize,
            HttpServletRequest request)
    {
        entity.setProductStatus(4);
        return productService.pageSearchList(pageNum, pageSize, entity, request);
    }
}
